/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmKhachHang.java
 *
 * Created on May 12, 2011, 1:40:28 PM
 */

package Presentation;

import RSCall.HinhAnhRSc;
import RSCall.NoiDungRSc;
import Entities.HINHANH;
import Entities.NOIDUNGQC;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.sql.Date;
import javax.swing.JFileChooser;
/**
 *
 * @author VooKa
 */
public class frmNoiDungQC extends javax.swing.JInternalFrame {
    
    /** Creates new form frmKhachHang
     * @param maND */
    public frmNoiDungQC(String maND) {        
        // Khởi tạo một số biến
        MaND = maND;  
        initComponents();
        Creation();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        pnlInfo = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAreaThongTinDiaOc = new javax.swing.JTextArea();
        tbxMoTa = new javax.swing.JTextField();
        btnUpdate = new javax.swing.JButton();
        pnlImg = new javax.swing.JPanel();
        pnlMoTaAnh = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtThoiGianChupAnh = new javax.swing.JTextField();
        txtMoTaAnh = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnDeleteImage = new javax.swing.JButton();
        btnUpdateImage = new javax.swing.JButton();
        btnAddImage = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setTitle(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("adcontent"));
        setFont(new java.awt.Font("Calibri", 0, 10)); // NOI18N
        setName("frmKhachHang"); // NOI18N
        setPreferredSize(new java.awt.Dimension(999, 670));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        pnlInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("thongTinDiaOc")));
        pnlInfo.setFont(new java.awt.Font("Calibri", 0, 10)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jLabel1.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("adcontent"));

        jLabel2.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jLabel2.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("describe"));

        txtAreaThongTinDiaOc.setEditable(false);
        txtAreaThongTinDiaOc.setColumns(20);
        txtAreaThongTinDiaOc.setLineWrap(true);
        txtAreaThongTinDiaOc.setRows(5);
        txtAreaThongTinDiaOc.setWrapStyleWord(true);
        txtAreaThongTinDiaOc.setAutoscrolls(false);
        jScrollPane2.setViewportView(txtAreaThongTinDiaOc);

        tbxMoTa.setEditable(false);

        btnUpdate.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("update"));
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlInfoLayout = new javax.swing.GroupLayout(pnlInfo);
        pnlInfo.setLayout(pnlInfoLayout);
        pnlInfoLayout.setHorizontalGroup(
            pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(31, 31, 31)
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnUpdate)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                    .addComponent(tbxMoTa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlInfoLayout.setVerticalGroup(
            pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInfoLayout.createSequentialGroup()
                .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlInfoLayout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(jLabel1)
                        .addGap(70, 70, 70)
                        .addGroup(pnlInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(tbxMoTa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(btnUpdate)
                .addGap(13, 13, 13))
        );

        pnlImg.setBorder(javax.swing.BorderFactory.createTitledBorder(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("image")));
        pnlImg.setPreferredSize(new java.awt.Dimension(600, 620));
        pnlImg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pnlImgMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                pnlImgMouseEntered(evt);
            }
        });

        javax.swing.GroupLayout pnlImgLayout = new javax.swing.GroupLayout(pnlImg);
        pnlImg.setLayout(pnlImgLayout);
        pnlImgLayout.setHorizontalGroup(
            pnlImgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 588, Short.MAX_VALUE)
        );
        pnlImgLayout.setVerticalGroup(
            pnlImgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 597, Short.MAX_VALUE)
        );

        pnlMoTaAnh.setBorder(javax.swing.BorderFactory.createTitledBorder(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("motahinhanh")));

        jLabel3.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("thoigianchupanh"));

        jLabel4.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("describe"));

        javax.swing.GroupLayout pnlMoTaAnhLayout = new javax.swing.GroupLayout(pnlMoTaAnh);
        pnlMoTaAnh.setLayout(pnlMoTaAnhLayout);
        pnlMoTaAnhLayout.setHorizontalGroup(
            pnlMoTaAnhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMoTaAnhLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlMoTaAnhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(txtThoiGianChupAnh, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMoTaAnh, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        pnlMoTaAnhLayout.setVerticalGroup(
            pnlMoTaAnhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMoTaAnhLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtMoTaAnh, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtThoiGianChupAnh)
                .addGap(18, 18, 18))
        );

        btnDeleteImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("delete"));
        btnDeleteImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteImageActionPerformed(evt);
            }
        });

        btnUpdateImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("update"));
        btnUpdateImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateImageActionPerformed(evt);
            }
        });

        btnAddImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("insert"));
        btnAddImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddImageActionPerformed(evt);
            }
        });

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Presentation/Bundle"); // NOI18N
        btnNext.setText(bundle.getString("Next")); // NOI18N
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });

        btnBack.setText(bundle.getString("Back")); // NOI18N
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnlMoTaAnh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnBack, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnUpdateImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnDeleteImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnAddImage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(pnlInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addComponent(pnlImg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlImg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnlInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(pnlMoTaAnh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnBack)
                                .addGap(18, 18, 18)
                                .addComponent(btnNext)
                                .addGap(18, 18, 18)
                                .addComponent(btnAddImage)
                                .addGap(18, 18, 18)
                                .addComponent(btnUpdateImage)
                                .addGap(18, 18, 18)
                                .addComponent(btnDeleteImage)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        LoadData();
    }//GEN-LAST:event_formInternalFrameOpened

    // Xử lý chọn file ảnh
    // Xử lý Sửa ảnh
    private void btnUpdateImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateImageActionPerformed
        if (btnUpdateImage.getText().equals(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("update"))) {           // Bắt đầu Sửa ảnh
            isAddImage = 2;
            btnUpdateImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"));
            JFileChooser f = new JFileChooser("../Images/");
            Anh = "";
            if (f.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                Anh = f.getSelectedFile().getName();
            }            
        }else if (btnUpdateImage.getText().equals(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"))){     // Sửa ảnh xong
            int maHinhAnh = imageList.get(nowShow).getMaHinhAnh();
            if (ValidationImage(Anh)) {
                String moTa = txtMoTaAnh.getText().trim();
                Date thoiGianChupAnh = new Date(200);
                if (txtThoiGianChupAnh.getText().equals("")) {
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("chuanhapthoigianchupanh"));
                    return;
                }
                try{
                    String temp = txtThoiGianChupAnh.getText();
                    thoiGianChupAnh = Date.valueOf(temp);
                }catch(IllegalArgumentException e){
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("invalidday"));
                    return;
                }
                String maND = MaND;            
                try {
                    dbHinhAnh.Update(maHinhAnh, Anh, moTa, thoiGianChupAnh, maND);
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("updateimagesuccess"));
                }catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, ex.toString());
                }
            }else if(Anh.equals("")){
                String moTa = txtMoTaAnh.getText().trim();
                Date thoiGianChupAnh = new Date(200);
                if (txtThoiGianChupAnh.getText().equals("")) {
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("chuanhapthoigianchupanh"));
                    return;
                }
                try{
                    String temp = txtThoiGianChupAnh.getText();
                    thoiGianChupAnh = Date.valueOf(temp);
                }catch(IllegalArgumentException e){
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("invalidday"));
                    return;
                }
                String maND = MaND;            
                try {
                    dbHinhAnh.Update(maHinhAnh, imageList.get(nowShow).getAnh(), moTa, thoiGianChupAnh, maND);
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("updateimagesuccess"));
                }catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, ex.toString());
                }
            }else JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("invalidimage"));
            ReviewImage();
            isAddImage = 0;
            btnUpdateImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("update"));
        }
        UpdateButtonState();
}//GEN-LAST:event_btnUpdateImageActionPerformed
    
    // Thêm ảnh
    private void btnAddImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddImageActionPerformed
        // TODO add your handling code here:
        if (btnAddImage.getText().equals(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("insert"))) {             // Bắt đầu thêm ảnh
            Anh = "";
            isAddImage = 1;
            btnAddImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"));
            JFileChooser f = new JFileChooser();
            int returnValue = f.showOpenDialog(null);
            if (returnValue == JFileChooser.APPROVE_OPTION) {
                Anh = f.getSelectedFile().getName();
            }
        }else if (btnAddImage.getText().equals(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"))){        // Thêm ảnh xong
            if (ValidationImage(Anh) && !Anh.equals("")) {
                String moTa = txtMoTaAnh.getText().trim();
                Date thoiGianChupAnh = new Date(200);
                if (txtThoiGianChupAnh.getText().equals("")) {
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("chuanhapthoigianchupanh"));
                    return;
                }
                try{
                    String temp = txtThoiGianChupAnh.getText();
                    thoiGianChupAnh = Date.valueOf(temp);
                }catch(IllegalArgumentException e){
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("invalidday"));
                    return;
                }
                String maND = MaND;
                try{
                    dbHinhAnh.Insert(Anh, moTa, thoiGianChupAnh, maND);
                    JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("insertimagesuccess"));
                    nowShow = imageList.size();
                }catch(Exception ex){
                    JOptionPane.showMessageDialog(this, ex.toString());
                }
            }else JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("invalidimageupdatefail"));
            
            ReviewImage();
            isAddImage = 0;
            btnAddImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("insert"));
        }
        UpdateButtonState();
}//GEN-LAST:event_btnAddImageActionPerformed

    // Xử lý xem ảnh kế tiếp
    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
        // TODO add your handling code here:
        nowShow++;
        UpdateImage();
        this.revalidate();
}//GEN-LAST:event_btnNextActionPerformed

    // Xử lý xem ảnh vừa xem
    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
        // TODO add your handling code here:
        nowShow--;
        UpdateImage();
        this.revalidate();
}//GEN-LAST:event_btnBackActionPerformed

    // Xóa ảnh
    private void btnDeleteImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteImageActionPerformed
        // TODO add your handling code here:
        int i = JOptionPane.showConfirmDialog(this, java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("really delete"),
                java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("warn"), JOptionPane.YES_NO_OPTION);
        if (i == 0) {
            try{
                dbHinhAnh.Delete(imageList.get(nowShow).getMaHinhAnh());
                imageList.remove(nowShow);
                nowShow--;
                if (nowShow < 0) {
                    nowShow = 0;
                }
                UpdateImage();
                this.revalidate();
                
            }catch(Exception e){
                JOptionPane.showMessageDialog(this, e.toString());
            }
        }
    }//GEN-LAST:event_btnDeleteImageActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        if (btnUpdate.getText().equals(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("update"))) {
            txtAreaThongTinDiaOc.setEditable(true);
            tbxMoTa.setEditable(true);
            btnUpdate.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"));
        }else{
            txtAreaThongTinDiaOc.setEditable(false);
            tbxMoTa.setEditable(false);
            String thongTinDiaOc = txtAreaThongTinDiaOc.getText().trim();
            String moTaTomTat = tbxMoTa.getText().trim();
            try {
            RSCall.NoiDungRSc noiDung = new NoiDungRSc();
                noiDung.Update(MaND, thongTinDiaOc, moTaTomTat);
                btnUpdate.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("update"));
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, ex.toString());
            }
        }
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void pnlImgMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlImgMouseEntered
//        pnlImg.setBorder(new ButtonBorder());
    }//GEN-LAST:event_pnlImgMouseEntered

    private void pnlImgMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlImgMouseClicked
        ImageViewX i = new ImageViewX(Anh);
        i.show();
        this.getParent().add(i,0);
    }//GEN-LAST:event_pnlImgMouseClicked

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddImage;
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnDeleteImage;
    private javax.swing.JButton btnNext;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JButton btnUpdateImage;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel pnlImg;
    private javax.swing.JPanel pnlInfo;
    private javax.swing.JPanel pnlMoTaAnh;
    private javax.swing.JTextField tbxMoTa;
    private javax.swing.JTextArea txtAreaThongTinDiaOc;
    private javax.swing.JTextField txtMoTaAnh;
    private javax.swing.JTextField txtThoiGianChupAnh;
    // End of variables declaration//GEN-END:variables
    
    private RSCall.NoiDungRSc dbNoiDungQC;
    private ArrayList<HINHANH> imageList;                    // List quản lý các ảnh của nội dung quảng cáo
    private String MaND = null;                                     // Giá trị của Mã nội dung hiện tại
    private int nowShow;                                            // Index của ảnh hiện tại
    private Image image = null;                                     // Biến lưu giữ ảnh
    private HinhAnhRSc dbHinhAnh;                           // Đối tượng HinhAnhRSc
    private String Anh = null;                                      // Tên file ảnh hiện tại
    private int isAddImage;                                         // Biến kiểm tra lúc thêm ảnh
    
    private void Creation(){
        try {
            imageList = new ArrayList<HINHANH>();
            dbHinhAnh = new HinhAnhRSc();
            dbNoiDungQC = new NoiDungRSc();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.toString());
            Logger.getLogger(frmNoiDungQC.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void LoadData(){
        try {
            
            nowShow = 0;
            isAddImage = 0;
        
            if (dbHinhAnh.IsMaND_HinhAnhExist(MaND)) {
                    imageList = dbHinhAnh.SelectHinhAnhByMaND(MaND);
            }
            pnlImg.setLayout(new FlowLayout());
            UpdateImage();
            
            txtAreaThongTinDiaOc.setText(dbNoiDungQC.GetRowByID(MaND).getThongTinDiaOc().trim());
            NOIDUNGQC nd = dbNoiDungQC.GetRowByID(MaND);
            String s = nd.getMoTaTomTat().trim();
            tbxMoTa.setText(s);
            
        }catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
            Logger.getLogger(frmNoiDungQC.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // Hàm cập nhật ảnh
    private void UpdateImage() {     
        if (!imageList.isEmpty()) {
            Anh = imageList.get(nowShow).getAnh();
            URL url = getClass().getResource("../Images/" + Anh);
            image = Toolkit.getDefaultToolkit().getImage(url).
                    getScaledInstance(540, 580, BufferedImage.SCALE_SMOOTH);
            ImageIcon icon = new ImageIcon(image);
            JLabel l = new JLabel(icon, JLabel.CENTER);
  
            pnlImg.removeAll();
            pnlImg.add(l);

            // Load các thông tin khác của HINHANH
            txtMoTaAnh.setText(imageList.get(nowShow).getMoTa().trim());
            txtThoiGianChupAnh.setText(imageList.get(nowShow).getThoiGianChupAnh().toString());
            UpdateButtonState();
        }      
    }

    // Hàm cập nhật các trạng thái của các Button
    private void UpdateButtonState() {        
        if (isAddImage == 1) {
            btnAddImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"));
            btnAddImage.setEnabled(true);
            btnBack.setEnabled(false);
            btnUpdateImage.setEnabled(false);
            btnDeleteImage.setEnabled(false);
            btnNext.setEnabled(false);
        }else if(isAddImage == 2){
            btnUpdateImage.setText(java.util.ResourceBundle.getBundle("Presentation/" + frmMain.resource).getString("done"));
            btnAddImage.setEnabled(false);
            btnBack.setEnabled(false);
            btnUpdateImage.setEnabled(true);
            btnDeleteImage.setEnabled(false);
            btnNext.setEnabled(false);
        }
        else{
            if (nowShow == 0) {
                btnBack.setEnabled(false);
            }else btnBack.setEnabled(true);
            if (nowShow == imageList.size() - 1) {
                btnNext.setEnabled(false);
            }else btnNext.setEnabled(true);
            btnAddImage.setEnabled(true);
            btnUpdateImage.setEnabled(true);
            btnDeleteImage.setEnabled(true);
        }
    }
    
    
    
    // Hàm kiểm tra file ảnh hợp lệ
    private boolean ValidationImage(String s){
        if (s.endsWith(".jpg") || s.endsWith(".png") || s.endsWith(".bmp")) {
            return true;
        }
        else return false;
    }
    
    // Cập nhật lại hình ảnh sau khi Thêm hoặc sửa
    private void ReviewImage(){
        try {
            imageList = dbHinhAnh.SelectHinhAnhByMaND(MaND);
        }catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.toString());
            return;
        }
        
        //frmMain.setEnabledForAll(pnlAddImage, false);
        UpdateImage();
        this.revalidate();
    }
}